<template>
	<div id="app" @click="viewClili" :class="style ? 'theme1' : ''">
		<router-view></router-view>
	</div>
</template>

<script>
	import bus from '@/utils/bus';
	import store from '@/store/index.js';
	export default {
		data() {
			return {
				style: false
			}
		},
		mounted() {
			document.addEventListener('contextmenu', this.preventDefault);
		},
		created() {
			bus.$on('global_theme', (msg) => { // 接收子组件传来 global_theme 的值
				this.style = msg;
			});
			//在页面加载时读取sessionStorage里的状态信息
			if (sessionStorage.getItem("store")) {
				this.$store.replaceState(
					Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem("store")))
				)
			}
			//在页面刷新时将vuex里的信息保存到sessionStorage里
			window.addEventListener("beforeunload", () => {
				sessionStorage.setItem("store", JSON.stringify(this.$store.state))
			})
		},
		methods: {
			viewClili() {

				this.$store.dispatch('removeSearche');
				this.$store.dispatch('removeMiniSearche');
				// / this.$store.dispatch('setMiniSearche');
			},
			preventDefault(event) {
				if (event.target.tagName.toLowerCase() === 'img') {
					event.preventDefault();
				}
				if (event.target.tagName.toLowerCase() === 'video') {
					event.preventDefault();
				}
				if (event.target.className.toLowerCase() === 'banner') {
					event.preventDefault();
				}
			}
		}
	}
</script>
